#pragma once

#include "plane.h"

class TiXmlNode;

class ExPortal
{
public:

	typedef std::vector<Common::Vector3> PortalVectors;
	typedef PortalVectors::iterator ItrPortalVectors;

	ExPortal(void);
	~ExPortal(void);

	bool Init( INode* pMaxNode, Mesh* pPortalShape, TimeValue timeNow, bool snapVertices );

	bool CreateConvexHull(void);

	bool Save( TiXmlNode* pBoundarySection );

	int  AddVertex( const Common::Vector3& bv, bool snapVertices );

	bool CullHull( const std::vector<Common::Plane>& rBoundaryPlanes, bool& bIsCulled );

	//return on which boundary.
	//if return value equal to -1, means no one matches
	int OnBoundary( const std::vector<Common::Plane>& rBoundaryPlanes );

private:

	bool _CullByPlane( std::vector<Common::Vector3>& convex, const Common::Plane& plane );

private:
	
	PortalVectors m_PortalVectors;
	Matrix3 m_matPortalMatrixl;
};

